﻿<UserControl x:Class="FunctionPoint.UserControls.FunctionPointSelectorTreeControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:FunctionPoint.Converters"
             xmlns:objects="clr-namespace:FunctionPoint.Objects"
             xmlns:wpft="http://schemas.xceed.com/wpf/xaml/toolkit"
             
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FunctionPoint;component/Resources/SharedResourcesDictionary.en-us.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
  
    </UserControl.Resources>
    <Grid HorizontalAlignment="Stretch" >
        <Grid.Resources>


            <Style TargetType="Grid" x:Key="styleGridPanelHeader">
                <Setter Property="Background" Value="LightGray"></Setter>
            </Style>

          
            <converters:NestLevelToMarginConverter x:Key="nestLevelToMarginConverter" RightMargin="2" BottomMargin="1" TopMargin="2"/>


            <DataTemplate x:Key="templateWorkItemQueryFolder" DataType="objects:WorkItemQueryFolder" >
                <StackPanel Orientation="Horizontal" Margin="{Binding NestLevel, Converter={StaticResource nestLevelToMarginConverter}}">
                    <Image Source="{StaticResource imgQueryFolder_Closed}"></Image>
                    <TextBlock Text="{Binding Name}"></TextBlock>
                </StackPanel>
            </DataTemplate>

            <DataTemplate x:Key="templateWorkItemQuery" >
                <StackPanel Orientation="Horizontal" Margin="{Binding NestLevel, Converter={StaticResource nestLevelToMarginConverter}}">
                    <Image Source="{StaticResource imgQuery}"></Image>
                    <TextBlock Text="{Binding Name}"></TextBlock>
                </StackPanel>
            </DataTemplate>

            <objects:WorkItemQueryComboBoxTemplateSelector x:Key="workItemQueryComboBoxTemplateSelector" 
                                                       WorkItemQueryFolderTemplate="{StaticResource templateWorkItemQueryFolder}"
                                                       WorkItemQueryTemplate="{StaticResource templateWorkItemQuery}"></objects:WorkItemQueryComboBoxTemplateSelector>

        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition MaxHeight="33" />
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Name="grdTopSelectorWindow" Style="{StaticResource styleGridPanelHeader}"  HorizontalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>

            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" >
                <TextBlock VerticalAlignment="Center">Query:</TextBlock>
                <ComboBox Name="cmbSelectedQuery" Margin="10,2,2,2"  MinWidth="400" ItemsSource="{Binding QueryHierarchyFlat}" ItemTemplateSelector="{StaticResource workItemQueryComboBoxTemplateSelector}" SelectionChanged="cmbSelectedQuery_SelectionChanged" SelectedValue="{Binding SelectedQuery}"></ComboBox>
                <Button Margin="10,4,4,4" Click="Button_Click">Refresh</Button>
            </StackPanel>


        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200*"></ColumnDefinition>
                
            </Grid.ColumnDefinitions>
   
            <ScrollViewer Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                <ScrollViewer.Resources>
                    <HierarchicalDataTemplate x:Key="WorkItemHierarchyTemplate" ItemsSource="{Binding ChildWorkItems}">
                        <Grid IsEnabled="{Binding IsEnabled}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="300"></ColumnDefinition>
                                <ColumnDefinition></ColumnDefinition>
                                <!--<ColumnDefinition></ColumnDefinition>-->
                            </Grid.ColumnDefinitions>

                            <!---->
                            
                            <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" IsChecked="{Binding IsSelected}">
                                <TextBlock Text="{Binding Title}"></TextBlock>
                            </CheckBox>
                            <wpft:ColorPicker Grid.Column="1" SelectedColor="{Binding BackgroundColor}" MinWidth="125"></wpft:ColorPicker>

                        </Grid>

                    </HierarchicalDataTemplate>
                </ScrollViewer.Resources>

                <TreeView ItemTemplate="{StaticResource WorkItemHierarchyTemplate}"  ItemsSource="{Binding ElementName=cmbSelectedQuery, Path=SelectedItem.WorkItems}">

                </TreeView>
            </ScrollViewer>
            
                
            
                        
        </Grid>
        
    </Grid>
</UserControl>
